home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / util / gnu / cvs-1.11.1p1.lha / contrib / dirfns.shar / seekdir.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-28  |  617 b   |  33 lines

  1. static char sccsid[] = "@(#)seekdir.c 4.9 3/25/83";
  2.  
  3. #include <sys/param.h>
  4. #include <dir.h>
  5.  
  6. /*
  7.  * seek to an entry in a directory.
  8.  * Only values returned by "telldir" should be passed to seekdir.
  9.  */
  10. void
  11. seekdir(dirp, loc)
  12.     register DIR *dirp;
  13.     long loc;
  14. {
  15.     long curloc, base, offset;
  16.     struct direct *dp;
  17.     extern long lseek();
  18.  
  19.     curloc = telldir(dirp);
  20.     if (loc == curloc)
  21.         return;
  22.     base = loc & ~(DIRBLKSIZ - 1);
  23.     offset = loc & (DIRBLKSIZ - 1);
  24.     (void) lseek(dirp->dd_fd, base, 0);
  25.     dirp->dd_size = 0;
  26.     dirp->dd_loc = 0;
  27.     while (dirp->dd_loc < offset) {
  28.         dp = readdir(dirp);
  29.         if (dp == NULL)
  30.             return;
  31.     }
  32. }
  33.